






//direction control
module Direction_control(

	input		clk,
	input		rst,
	
	
	
	input		up,
	input		down,
	input		left,
	input		right,



	output[3:0]	direction
);

/*
	1. 0001 : up
	2. 0010 : down
	3. 0100 : left
	4. 1000 : right
*/
reg[3:0]	dir_reg;  //direction regiseter save current direction


assign direction = dir_reg;


always@(posedge clk or negedge rst)
begin
	if(rst == 1'b0)
		dir_reg <= 4'b0100;
	else if(up == 1'b1 && dir_reg != 4'b0010)
		dir_reg <= 4'b0001;
	else if(down == 1'b1 && dir_reg != 4'b0001)
		dir_reg <= 4'b0010;
	else if(left == 1'b1 && dir_reg != 4'b1000)
		dir_reg <= 4'b0100;
	else if(right == 1'b1 && dir_reg != 4'b0100)
		dir_reg <= 4'b1000;
	else
		dir_reg <= dir_reg;
end


endmodule 